package com.ytd.common.dialog;

import android.content.Context;
import android.view.Gravity;
import android.widget.TextView;

import com.ytd.common.R;

import pl.droidsonroids.gif.GifImageView;

public class ProgressDialog extends HideNavigationDialog {
    private TextView waitText;
    private GifImageView mGifImageView;
    private String text;

    public ProgressDialog(Context context) {
        super(context);//设置样式
        getWindow().setGravity(Gravity.CENTER);
        setContentView(R.layout.dialog_progress);
        waitText = findViewById(R.id.dialog_txt);
        mGifImageView = findViewById(R.id.iv_dialog_gif);
        this.setCanceledOnTouchOutside(false);
        //设置点击返回键不消失
        this.setCancelable(false);
    }

    public void setText(String text) {
        this.text = text;
        waitText.setText(text);
    }

    public void setImage(int res) {
        mGifImageView.setImageResource(res);
    }

    public void resetImage() {
        mGifImageView.setImageResource(R.drawable.gif_progress);
    }

    @Override
    public void show() {
        waitText.setText(text);
        super.show();
    }

    @Override
    public void dismiss() {
        super.dismiss();
        text = "";
        resetImage();
    }
}